<?php

/*
 * This file is part of the sfSAMLplugin package.
 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
 * (c) 2010      Théophile Helleboid <t.helleboid@iariss.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * sfSAMLPlugin configuration.
 * 
 * @package    sfSAMLPlugin
 * @subpackage sfSAMLAuth
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
 * @author     Théophile Helleboid <t.helleboid@iariss.fr>
 */
class BasesfSAMLAuthActions extends sfActions
{

 public function executeTwocheckout($request)
 {
   
   //recibo los parametros de compra

   
  


  $simpleSAMLAuth = new SimpleSAML_Auth_Simple('default-sp');
  if ($simpleSAMLAuth->isAuthenticated())
  {
     
     $plataforma = $this->getUser()->getAttribute('des_plataforma_twocheckout',null);
     if($plataforma!=null)
     {
        return $this->redirect('planes/'.$plataforma);
     }
     else
     {
        return $this->redirect('@homepage');
     }
   


  }else{
          $simpleSAMLAuth->login();
  }

  
   
 }

  public function executeSignin($request)
  {

    $user = $this->getUser();
    //si estas autenticado en la aplicacion symfony
  


    // Create SimpleSAML module
    $simpleSAMLAuth = new SimpleSAML_Auth_Simple('default-sp');
    
    // If the user is authenticated from the IdP
    if ($simpleSAMLAuth->isAuthenticated())
    {
      
        if ($user->isAuthenticated())
          {
            return $this->redirect('@homepage');
          }
         else{
           //aca ya estas autenticado en SAML pero no en la aplicion symfony
           return $this->redirect('prueba/faltasymfony');
         } 
    }
    else  
    {
       
       $this->url_idp = $simpleSAMLAuth->login();
      
    }


  }

  public function executeSignout($request)
  {
   

    $signoutUrl = sfConfig::get('app_sf_guard_plugin_success_signout_url');

    $simpleSAMLAuth = new SimpleSAML_Auth_Simple('default-sp');
    $simpleSAMLAuth->logout($this->generateUrl('' != $signoutUrl ? $signoutUrl : 'homepage'), array(), true);
    // Nothing happen after there
    

    $this->redirect('' != $signoutUrl ? $signoutUrl : 'homepage');
  }

  public function executeSecure($request)
  {
    $this->getResponse()->setStatusCode(403);
  }

  public function executePassword($request)
  {
    throw new sfException('This method is not yet implemented.');
  }
}
